package lupita.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import lupita.model.vos.FileSystemItem;

import org.apache.lucene.index.Term;


public class UtilsSearcher {
	
	public static Term[] getListWords(List<String> liTerms, String input) {
		// se consiguen los terminos
		Term[] arrayWords = new Term[liTerms.size()];
		for(int i=0; i<liTerms.size(); i++) {
			arrayWords[i] = new Term(input, liTerms.get(i));
		}
		
		return arrayWords;
	}
	
	public static List<String> getTagsInSearchInput(String searchInput) {
		// la busqueda se standariza a minusculas
		searchInput = searchInput.toLowerCase();
		
		String[] arraySearchInput = searchInput.split(" ");	
		
		List<String> tagsInSearch = new ArrayList<String>(Arrays.asList(arraySearchInput));
		
		tagsInSearch.remove("");
		
		return tagsInSearch;
	}
	

	
	public static List<FileSystemItem> searchByMediaName(List<FileSystemItem> listFileRepo, List<String> qTerms) {
		
		List<FileSystemItem> resultListFileRepo = new ArrayList<FileSystemItem>();
		
		for(FileSystemItem fileRepo: listFileRepo){			
			String fileName = fileRepo.getFileName();
			
			for(String term: qTerms) ITERATE_TERMS: {
				if(fileName.contains(term)) {
					resultListFileRepo.add(fileRepo);
					break ITERATE_TERMS;
				}				
			}			
		}		
		
		return resultListFileRepo;
	}
	
	public static boolean mediaAllFiles(String searchType) {
		//definimos patrones para los tipos de archivos
		boolean ret = false;
		if( searchType.equalsIgnoreCase(".*[fF][lL][vV]|.*[mM][pP]3") ||
			searchType.equalsIgnoreCase(".*[mM][pP]3") ||  
			searchType.equalsIgnoreCase(".*[mM][pP]3|.*[fF][lL][vV]") ||
			searchType.equalsIgnoreCase(".*[fF][lL][vV]") 
		){
			ret = true;
		}
		
		return ret;
	}
	
}
